package com.raspositos.guitarfrik.android;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import android.content.Context;

public class StoreLinker {
	
	enum Stores {
		Amazon("Amazon"), 
		SheetMusicPlus("Sheet Music Plus.com"),
		MusicRoom("Music Room.com"),
		Unknown("");
		
		private String name;

		Stores(String name){
			this.name = name;
		}
		
		public static Stores findByName(String name){
			Stores st = Unknown;
			for (int i = 0; i < Stores.values().length; i++) {
				if (Stores.values()[i].name.equals(name)){
					st = Stores.values()[i];
					break;
				}
			}
			return st;
		}
	}
	
	public static String getLink(Context ctxt, Prefs prefs, TrackDescriptor track) throws UnsupportedEncodingException{
		String url = "http://code.google.com/p/guitarfrik/wiki/Help";
		Stores st  = Stores.findByName(prefs.getMusicStore());
		switch (st) {
		case Amazon:
//			url = "http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&t=guita0c7-20&o=1&p=21&l=ur1&" +
//					"category=books&field-keywords="+
//					URLEncoder.encode(track.getArtist() + " " + track.getAlbum(),"UTF-8")+"&f=ifr";
			url = "http://www.amazon.com/gp/search?ie=UTF8&keywords="+
					URLEncoder.encode(track.getArtist() + " " + track.getAlbum(),"UTF-8")+"+songbook&tag=guita0c7-20&index=books&linkCode=ur2&camp=1789&creative=9325";
			break;
		case SheetMusicPlus:
			url = "http://www.sheetmusicplus.com/s?id=440203&q=" + URLEncoder.encode(track.getArtist() + " " + track.getTitle(),"UTF-8");
			break;
		case MusicRoom:
			url = "http://www.musicroom.com/Search/gsearch.aspx?kbid=4282&media=Sheet+Music&searchtype=advanced&" +
									"artist="+ URLEncoder.encode(track.getArtist(),"UTF-8") +
									"&song=" + URLEncoder.encode(track.getTitle(),"UTF-8");
			break;
		default:
			break;
		}
		return url;
	}
}
